package UI;

import java.util.*;
import Controller.*;

public class DVDUI
{
    private DVDCtr dvdctr;
    private static DVDUI instance = null;
    private MainUI mainUI;
    
    private DVDUI()
    {
        dvdctr = DVDCtr.getInstance();
        DVDMenuStart();
    }
    
    public static DVDUI getInstance()
    {
        if(instance == null)
        {
            instance = new DVDUI();
        }
        return instance;
    }
    
    // starts DVD menu
    public void DVDMenuStart()
    {
        boolean exit = false;
        while(!exit)
        {
            int choice = printDVDMenu();
            switch (choice)
            {
                case 1: createDVD();
                        break;
                case 2: createCopy();
                        break;
                case 3: findDVD();
                        break;
                case 4: findCopy();
                        break;
                case 5: listAllDVDs();
                        break;
                case 6: deleteDVD();
                        break;
                case 7: deleteCopy();
                        break;
                case 8: goBack();
                        break;
            }
        }
    }
    
    public int printDVDMenu()
    {
        Scanner keyboard = new Scanner(System.in);
        //System.out.print('\f');
        System.out.println("*** DVD Menu ***");
        System.out.println("1. Create DVD");
        System.out.println("2. Create Copy");
        System.out.println("3. Find DVD");
        System.out.println("4. Find Copy");
        System.out.println("5. List all DVDs with copies");
        System.out.println("6. Delete DVD");
        System.out.println("7. Delete Copy");
        System.out.println("8. Go back");
        System.out.println("Your choice #: ");
        
        int choice = keyboard.nextInt();
        return choice;
    }
    
    public void createDVD()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.print('\f');
        System.out.println("DVD title");
        String title = keyboard.nextLine();
        System.out.println("DVD artist");
        String artist = keyboard.nextLine();
        System.out.println("DVD publication date");
        String pubDate = keyboard.nextLine();
        
        dvdctr.createDVD(title, artist, pubDate);
    }
    
    public void createCopy()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.print('\f'); 
        System.out.println("DVD ID");
        int dvdId = Integer.parseInt(keyboard.nextLine());
        System.out.println("Serial Number");
        String serialNumber = keyboard.nextLine();
        System.out.println("Purchase Date");
        String purchaseDate = keyboard.nextLine();
        System.out.println("Purchase Price");
        String purchasePrice = keyboard.nextLine();
        
        dvdctr.createCopy(dvdId, serialNumber, purchaseDate, purchasePrice);
    }
    
    public void findDVD()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.print('\f');
        System.out.println("Type DVD title");
        String dvdTitle = keyboard.nextLine();
        
        System.out.println(dvdctr.findDvd(dvdTitle));
    }
    
    public void findCopy()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.print('\f');
        System.out.println("Type serial number");
        String serialNumber = keyboard.nextLine();
        
        System.out.println(dvdctr.findCopyInfo(serialNumber));
    }
    
    public void listAllDVDs()
    {
        System.out.print('\f'); 
        String listAllData = dvdctr.listAllDvds();
        System.out.println(listAllData);
    }
    
    public void deleteDVD()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.print('\f'); 
        System.out.println("Type DVD ID");
        int dvdId = Integer.parseInt(keyboard.nextLine());
        
        dvdctr.deleteDvd(dvdId);
    }
    
    public void deleteCopy()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.print('\f'); 
        System.out.println("Type copy serial number");
        String serialNumber = keyboard.nextLine();
        
        dvdctr.deleteCopy(serialNumber);
    }
    
    // calls and returns to main menu
    public void goBack()
    {
        mainUI.getInstance().mainMenuStart();
    }
}
